const express = require('express')
const bodyParser = require('body-parser')
let app = new express()
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: true }))
app.all('*', function(req, res, next) {
    // CORS headers
    res.header("Access-Control-Allow-Origin", "*") // restrict it to the required domain
    res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS')
    // Set custom headers for CORS
    res.header("Content-Type", "application/json;charset=utf-8")
    res.header('Access-Control-Allow-Headers', 'Content-type,Accept,X-Access-Token,X-Key,Authorization')
    if (req.method == 'OPTIONS') {
      res.status(200).end()
    } else {
      next()
    }
})
const userRoute = require('./routes/userRoute')
app.use('/', userRoute)

app.listen(5000,()=>{
    console.log('server is running at por 5000...')
})
